home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / NewPong-c / pong.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-04  |  16.0 KB  |  761 lines  |  [TEXT/MMCC]

  1. //• ——————————————————————————————•••———————————————————————————————•//
  2. //• Another old source project, brought back from the dead by        •//
  3. //• Kenneth A Long, at itty bitty bytes(tm)!                        •//
  4. //• ——————————————————————————————•••———————————————————————————————•//
  5.  
  6. // 18-Jun-88 14:52:30-MDT,16523;000000000001
  7. // Return-Path: <u-lchoqu%sunset@cs.utah.edu>
  8. // Received: from cs.utah.edu by SIMTEL20.ARPA with TCP; Sat, 18 Jun 88 14:52:07 MDT
  9. // Received: by cs.utah.edu (5.54/utah-2.0-cs)
  10. //     id AA22823; Sat, 18 Jun 88 14:52:05 MDT
  11. // Received: by sunset.utah.edu (5.54/utah-2.0-leaf)
  12. //     id AA24896; Sat, 18 Jun 88 14:52:01 MDT
  13. // Date: Sat, 18 Jun 88 14:52:01 MDT
  14. // From: u-lchoqu%sunset@cs.utah.edu (Lee Choquette)
  15. // Message-Id: <8806182052.AA24896@sunset.utah.edu>
  16. // To: rthum@simtel20.arpa
  17. // Subject: pong.c
  18.  
  19. /*            pong.c
  20.  The classic game of pong in Megamax C for the Mac.
  21.  Thanks to MacTutor (Vol 1, No. 5 April 1985 page 39) for 
  22.  animation techniques. If you are reading this and don't  
  23.  subscribe to MacTutor, consider it. No resource file is  
  24.  needed. This program, source and object, is in the
  25.  public domain and not for sale. 
  26.   
  27.  Author:    David L. O'Connor, 370 Eden St. Buffalo, N.Y. 
  28.             14220.  (716) 828-0898.   CIS - 70265,1172 
  29.  Date  :    July, 1985   Version 2 
  30. */
  31.  
  32. #include    <stdio.h>
  33. #include    <sound.h>
  34.  
  35. /* the game directions */
  36. #define    STOPPED 0
  37. #define    UP 1
  38. #define    DOWN 2
  39. #define    LEFT 3
  40. #define    RIGHT 4
  41. #define    UP_LEFT 5
  42. #define    UP_RIGHT 6
  43. #define    DOWN_LEFT 7
  44. #define    DOWN_RIGHT 8
  45.  
  46. /* paddle + ball dimensions */
  47. #define    PADWIDTH 10
  48. #define    PADLENGTH 45
  49. #define    PADINSET 10
  50. #define    BALLWIDTH 9
  51. #define    BALLLENGTH 9
  52.  
  53. #define    BALLSPEED 7
  54. #define    PADDLESPEED 9
  55. #define    HIGHSCORE 21
  56.  
  57. /* the menu ids */
  58. #define    appleID 128    
  59. #define    fileID  129
  60. #define    editID  130
  61. #define    skillID 131
  62. #define    soundID 132
  63.  
  64. /* from the MAC's standard pattern list */
  65. #define    PAD_PAT qd.dkGray    //((*pat_handle)->pat_list[6])
  66. #define    WALL_PAT qd.gray    //((*pat_handle)->pat_list[4])
  67.  
  68. typedef struct{
  69.     short pat_cnt;
  70.     Pattern pat_list[38];
  71. } sys_patterns;
  72.  
  73. typedef struct {
  74.     Rect r;
  75.     short dir;
  76.     short speed;
  77.     short score;
  78. } paddle;
  79.     
  80. typedef struct {
  81.     RgnHandle    rgn;
  82.     RgnHandle    oldRgn;
  83.     RgnHandle    unRgn;
  84.     short dir;
  85.     short speed;
  86.     short on;
  87. } target;
  88.  
  89. typedef struct {
  90.     short mode;
  91.     Tone triplet[1];
  92. } bleep_tag;
  93.         
  94. typedef struct {
  95.     short mode;
  96.     Tone triplet[2];
  97. } blat_tag;
  98.     
  99. static bleep_tag bleep_buf;
  100. static blat_tag  blat_buf;
  101. static paddle l_paddle, r_paddle;
  102. static target ball;
  103. static sys_patterns **pat_handle;
  104. static WindowPtr gameWindow, which_window, aboutWindow;
  105. static WindowRecord winStorage;
  106. static Rect r, r2, dragRect, top_wall, bottom_wall;
  107. static EventRecord gameEvent;
  108. static MenuHandle gameMenu[5];
  109. static char menuTitle[1];
  110. static short skill_level, done, paused, last_won, volleys, sound_on;
  111. static char title[] = {
  112.     "\pLeft 00 - Mac Pong - Right 00"
  113. //•    12345678901234567890123456789
  114. };
  115.  
  116. main() 
  117. {
  118.     SetUp();
  119.     HideCursor ();
  120.     
  121.     while (! done)
  122.     {
  123.         Handle_Events();
  124.         Play_Pong();
  125.     }
  126.     FlushEvents(everyEvent, 0);
  127. //    StopSound();
  128.     ExitToShell();
  129. }
  130.  
  131. SetUp()
  132. {
  133.     done = 0;
  134.     skill_level = 2;
  135.     sound_on = 1;
  136.     last_won = RIGHT;
  137.     InitGraf(&qd.thePort);
  138.     InitFonts();
  139.     InitWindows();
  140.     TEInit();
  141.     InitDialogs(0);
  142.     InitCursor();
  143.     InitSounds();
  144.     
  145.     pat_handle = (sys_patterns**) GetResource('PAT#', 0);
  146.  
  147.     FlushEvents(everyEvent, 0);
  148.  
  149.     SetRect(&r, 4, 40, 508, 338);
  150.     SetRect(&dragRect, 4, 24, r.right - 4, r.bottom - 4);
  151.     
  152. //     gameWindow = NewWindow(&winStorage, 
  153. //                 &r, "\pLeft 00 MAC_Pong Right 00", 
  154. //                  1, rDocProc, (WindowPtr)-1L, 0, 0L);
  155.                  
  156.     gameWindow = NewWindow(&winStorage, &r, (StringPtr) title, 1, rDocProc, (WindowPtr)-1L, 0, 0L);
  157.  
  158.     SetPort(gameWindow);
  159.     Build_Menus();
  160.     ShowCursor();
  161.     Create_L_Paddle();
  162.     Create_R_Paddle();
  163.     Create_Walls();
  164.     Create_Ball();
  165.     Init_Game();
  166. }
  167.  
  168. /* pretty much straight from SAMP in I.M. */
  169. Handle_Events()
  170. {
  171.     SystemTask(); 
  172.     if (GetNextEvent(everyEvent, &gameEvent))
  173.     {
  174.         switch (gameEvent.what)
  175.         {
  176.             case mouseDown:
  177.                 ShowCursor ();
  178.                 switch (FindWindow(gameEvent.where, &which_window))
  179.                 {
  180.                     case inMenuBar:
  181.                         DoCommand(MenuSelect(gameEvent.where));
  182.                     break;
  183.                     case inSysWindow:
  184.                         SystemClick(&gameEvent, which_window);
  185.                     break;
  186.                     case inDrag:
  187.                         DragWindow(which_window, gameEvent.where, &dragRect);
  188.                     break;
  189.                     case inContent:
  190.                         if (which_window != FrontWindow())
  191.                             SelectWindow(which_window);
  192.                     break;
  193.                 }
  194.             break;
  195.  
  196.             case keyDown: 
  197.             case autoKey:
  198.                 if ((gameEvent.modifiers & cmdKey) != 0)
  199.                 {
  200. //                    AdjustMenus();
  201.                     DoCommand(MenuKey((char) (gameEvent.message & charCodeMask)));
  202.                 }
  203.             break;
  204.  
  205.             case activateEvt:
  206.                 if (gameEvent.modifiers & activeFlag)
  207.                     Disable_Edit_Menu();
  208.                 else
  209.                     Enable_Edit_Menu();
  210.             break;
  211.             
  212.             case updateEvt:
  213.                 SetPort(gameWindow);
  214.                 BeginUpdate(gameWindow);
  215.                 FillRect(&l_paddle.r, &PAD_PAT);
  216.                 FillRect(&r_paddle.r, &PAD_PAT);
  217.                 FillRect(&top_wall, &WALL_PAT);
  218.                 FillRect(&bottom_wall, &WALL_PAT);
  219.                 if (ball.on)
  220.                     PaintRgn(ball.rgn);
  221.                 EndUpdate(gameWindow);
  222.             break;
  223.         }
  224.     }
  225. }
  226.  
  227. Play_Pong()
  228. {
  229.     if ( (! paused) && (l_paddle.score < HIGHSCORE && r_paddle.score < HIGHSCORE))
  230.     {
  231.         if (! ball.on)
  232.             Serve_Ball();
  233.         Check_Status();
  234.         Move_Left_Paddle();
  235.         Move_Right_Paddle();
  236.         Move_Ball();
  237.     }
  238. }
  239.  
  240. InitSounds()
  241. {
  242.     bleep_buf.mode = swMode;
  243.     bleep_buf.triplet[0].count = 1000;
  244.     bleep_buf.triplet[0].amplitude = 255;
  245.     bleep_buf.triplet[0].duration = 5;
  246.     blat_buf.mode = swMode;
  247.     blat_buf.triplet[0].count = 1000;
  248.     blat_buf.triplet[0].amplitude = 255;
  249.     blat_buf.triplet[0].duration = 5;
  250.     blat_buf.triplet[1].count = 3000;
  251.     blat_buf.triplet[1].amplitude = 255;
  252.     blat_buf.triplet[1].duration = 10; 
  253. }
  254.  
  255. Build_Menus()
  256. {
  257.     register short i;
  258.     
  259.     InitMenus();
  260.     gameMenu[0] = NewMenu(appleID, "\p\024");
  261.     gameMenu[1] = NewMenu(fileID, "\pFile");
  262.     gameMenu[2] = NewMenu(editID, "\pEdit");
  263.     gameMenu[3] = NewMenu(skillID, "\pSkill");
  264.     gameMenu[4] = NewMenu(soundID, "\pSound");
  265.     AppendMenu(gameMenu[0],"\pAbout \"Pong\"");
  266.     AddResMenu(gameMenu[0],'DRVR');
  267.     AppendMenu(gameMenu[1],"\pPause/P;Restart/R;Quit/Q");
  268.     AppendMenu(gameMenu[2],"\p(Undo/Z;(-;(Cut/X;(Copy/C;(Paste/V;(Clear");
  269.     AppendMenu(gameMenu[3],"\pBeginner/B;Novice/N;Normal;Expert/E");
  270.     AppendMenu(gameMenu[4],"\pSound Off/S");
  271.     for(i = 0; i < 5; i++)
  272.         InsertMenu(gameMenu[i], 0);
  273.     CheckItem(gameMenu[3], skill_level, 1);
  274.     DrawMenuBar();
  275. }
  276.  
  277. Disable_Edit_Menu()
  278. {
  279.     DisableItem(gameMenu[2], 1);
  280.     DisableItem(gameMenu[2], 3);
  281.     DisableItem(gameMenu[2], 4);
  282.     DisableItem(gameMenu[2], 5);
  283.     DisableItem(gameMenu[2], 6);
  284. }
  285.  
  286. Enable_Edit_Menu()
  287. {
  288.     EnableItem(gameMenu[2], 1);
  289.     EnableItem(gameMenu[2], 3);
  290.     EnableItem(gameMenu[2], 4);
  291.     EnableItem(gameMenu[2], 5);
  292.     EnableItem(gameMenu[2], 6);
  293. }
  294.  
  295. DoCommand (long menu_selection)
  296. {
  297.     register short the_item;
  298.     static char name[256];
  299.     
  300.     the_item = LoWord(menu_selection);
  301.     switch (HiWord(menu_selection))
  302.     {
  303.         case appleID:
  304.             GetItem(gameMenu[0], the_item, (StringPtr) name);
  305.             OpenDeskAcc((StringPtr) name);
  306.             SetPort(gameWindow);
  307.         break;
  308.         
  309.         case editID:
  310.             SystemEdit(the_item - 1);
  311.         break;
  312.         
  313.         case fileID:
  314.             switch (the_item)
  315.             {
  316.                 case 1:
  317.                     if (paused)
  318.                     {
  319.                         paused = 0;
  320.                         SetItem(gameMenu[1], 1, "\pPause");
  321.                         ShowCursor ();
  322.                     }
  323.                     else
  324.                         {
  325.                             paused = 1;
  326.                             SetItem(gameMenu[1], 1, "\pContinue");
  327.                             HideCursor ();
  328.                     }
  329.                 break;
  330.                 
  331.                 case 2:
  332.                     Init_Game();
  333.                     HideCursor ();
  334.                 break;
  335.                 
  336.                 case 3:
  337.                     done = 1;
  338.                 break;
  339.             }
  340.         break;
  341.         
  342.         case skillID:
  343.             CheckItem(gameMenu[3], skill_level, 0);
  344.             skill_level = the_item;
  345.             CheckItem(gameMenu[3], skill_level, 1);
  346.             HideCursor ();
  347.         break;
  348.         
  349.         case soundID:
  350.             if (sound_on)
  351.             {
  352.                 sound_on = 0;
  353.                 SetItem(gameMenu[4], 1, "\pSound On");
  354.             }
  355.             else
  356.                 {
  357.                     sound_on = 1;
  358.                     SetItem(gameMenu[4], 1, "\pSound Off");
  359.             }
  360.             HideCursor ();
  361.         break;
  362.     }
  363.     HiliteMenu(0);
  364. }
  365.  
  366. Create_L_Paddle()
  367. {    
  368.     l_paddle.dir = STOPPED;
  369.     l_paddle.speed = PADDLESPEED;
  370.     l_paddle.score = 0;
  371.     SetRect (&l_paddle.r, 
  372.             winStorage.port.portRect.left + PADINSET,
  373.             winStorage.port.portRect.top + PADINSET,
  374.             winStorage.port.portRect.left + PADINSET + PADWIDTH,
  375.             winStorage.port.portRect.top + PADINSET + PADLENGTH);
  376.     FillRect(&l_paddle.r, &PAD_PAT);
  377. }
  378.  
  379. Create_R_Paddle()
  380. {    
  381.     r_paddle.dir = STOPPED;
  382.     r_paddle.speed = PADDLESPEED;
  383.     r_paddle.score = 0;
  384.     SetRect (&r_paddle.r,
  385.             winStorage.port.portRect.right - PADWIDTH - PADINSET,
  386.             winStorage.port.portRect.top + PADINSET,
  387.             winStorage.port.portRect.right - PADWIDTH - PADINSET + PADWIDTH,
  388.             winStorage.port.portRect.top + PADINSET + PADLENGTH);
  389.     FillRect(&r_paddle.r, &PAD_PAT);    
  390. }    
  391.  
  392. Create_Walls()
  393. {
  394.     SetRect(&top_wall,
  395.             winStorage.port.portRect.left + 20,
  396.             winStorage.port.portRect.top + 5,
  397.             winStorage.port.portRect.right - 20, 
  398.             winStorage.port.portRect.top + 20);
  399.     FillRect(&top_wall, &WALL_PAT);
  400.     SetRect(&bottom_wall,
  401.             winStorage.port.portRect.left + 20,
  402.             winStorage.port.portRect.bottom - 20,
  403.             winStorage.port.portRect.right - 20,
  404.             winStorage.port.portRect.bottom - 5);
  405.     FillRect(&bottom_wall, &WALL_PAT);    
  406. }
  407.  
  408. Create_Ball()
  409. {
  410.     ball.rgn = NewRgn();
  411.     ball.oldRgn = NewRgn();
  412.     ball.unRgn = NewRgn();
  413.     ball.dir = LEFT;
  414.     ball.speed = BALLSPEED;
  415.     SetRect (&r, 250,  150, 250 + BALLWIDTH, 150 + BALLLENGTH);
  416.     OpenRgn();
  417.     FrameOval(&r);
  418.     CloseRgn(ball.rgn);
  419. }
  420.  
  421. Serve_Ball()
  422. {
  423.     register i;
  424.  
  425.     OffsetRgn(ball.rgn, 250 - ((**ball.rgn).rgnBBox.right),
  426.                         150 - ((**ball.rgn).rgnBBox.top) );
  427.     for (i = 0; i < 250; i++)
  428.     {
  429.         Check_Status();
  430.         Move_Right_Paddle();
  431.         Move_Left_Paddle();
  432.         Move_Ball();
  433.     }
  434.     ball.dir = (last_won == RIGHT) ? LEFT: RIGHT;
  435.     ball.speed = BALLSPEED;
  436.     ball.on = 1;
  437.     PaintRgn(ball.rgn);
  438.     Bleep();
  439. }
  440.  
  441. /* someone scored a point */
  442. Kill_Ball()
  443. {
  444.     ball.on = volleys = 0;
  445.     CopyRgn(ball.rgn, ball.unRgn);
  446.     EraseRgn(ball.rgn);
  447.     Recover_From_Collision();
  448.     Blat();
  449.     Display_Score();
  450. }
  451.  
  452. Init_Game()
  453. {
  454.     l_paddle.score = r_paddle.score = 0;
  455.     ball.speed = BALLSPEED;
  456.     Kill_Ball();
  457. }
  458.  
  459. /* check for bounces, direction changes, scoring, etc */
  460. Check_Status()
  461. {
  462.     static Rect *ball_r;
  463.  
  464.     register ball_top        = (**ball.rgn).rgnBBox.top;
  465.     register ball_bottom    = (**ball.rgn).rgnBBox.bottom;
  466.     register ball_left        = (**ball.rgn).rgnBBox.left;
  467.     register ball_right        = (**ball.rgn).rgnBBox.right;
  468.     
  469.     ball_r = &((**ball.rgn).rgnBBox);
  470.  
  471.     /* make it a little harder as time goes by */
  472.     if (volleys > 35)
  473.         ball.speed = BALLSPEED + 6;
  474.     else if (volleys > 30)
  475.         ball.speed = BALLSPEED + 5;
  476.     else if (volleys > 25)
  477.         ball.speed = BALLSPEED + 4;
  478.     else if (volleys > 20)
  479.         ball.speed = BALLSPEED + 3;
  480.     else if (volleys > 15)
  481.         ball.speed = BALLSPEED + 2;
  482.     else if (volleys > 10)
  483.         ball.speed = BALLSPEED + 1;
  484.         
  485.     r_paddle.speed = ball.speed + 2;
  486.         
  487.     /* the right paddle tries to track the ball */
  488.     if ( (ball_right > 250) &&
  489.          (ball.dir == UP_RIGHT || ball.dir == DOWN_RIGHT || 
  490.           ball.dir == RIGHT) ){
  491.         if (ball_top + Handicap() < r_paddle.r.top)
  492.             r_paddle.dir = UP;
  493.         else if (ball_bottom - Handicap() > r_paddle.r.bottom)
  494.             r_paddle.dir = DOWN;
  495.         else
  496.             r_paddle.dir = STOPPED;
  497.     }
  498.     else
  499.         r_paddle.dir = STOPPED;
  500.         
  501.     /* the ball and the left boundry */
  502.     if (ball_left < l_paddle.r.right ){
  503.         if (SectRect(ball_r, &l_paddle.r, &r))
  504.         {
  505.             volleys++;
  506.             Bleep();
  507.             if (ball_top <= l_paddle.r.top + 15)
  508.                 ball.dir = UP_RIGHT;
  509.             else if (ball_top > l_paddle.r.top + 15 && ball_bottom < l_paddle.r.top + 30)
  510.                 ball.dir = RIGHT;
  511.             else
  512.                 ball.dir = DOWN_RIGHT;
  513.         }
  514.         else{
  515.             last_won = RIGHT;
  516.             r_paddle.score++;
  517.             Kill_Ball();
  518.         }
  519.         return;
  520.     }
  521.     
  522.     /* the ball and the right boundry */
  523.     if (ball_right > r_paddle.r.left){
  524.         if (SectRect(ball_r, &r_paddle.r, &r)){
  525.             volleys++;
  526.             Bleep();
  527.             if (ball_top <= r_paddle.r.top + 15)
  528.                 ball.dir = UP_LEFT;
  529.             else if (ball_top > r_paddle.r.top + 15 && ball_bottom < r_paddle.r.top + 30)
  530.                 ball.dir = LEFT;
  531.             else
  532.                 ball.dir = DOWN_LEFT;
  533.         }
  534.         else{
  535.             last_won = LEFT;
  536.             l_paddle.score++;
  537.             Kill_Ball();
  538.         }
  539.         return;
  540.     }
  541.     
  542.     /* the ball and the top wall */
  543.     if (ball_top < top_wall.bottom){
  544.         if (ball.dir == UP_LEFT)
  545.             ball.dir = DOWN_LEFT;
  546.         else if (ball.dir == UP_RIGHT)
  547.             ball.dir = DOWN_RIGHT;
  548.         Bleep();
  549.         return;
  550.     }
  551.     
  552.     /* the ball and the bottom wall */
  553.     if (ball_bottom > bottom_wall.top){
  554.         if (ball.dir == DOWN_LEFT)
  555.             ball.dir = UP_LEFT;
  556.         else if (ball.dir == DOWN_RIGHT)
  557.             ball.dir = UP_RIGHT;
  558.         Bleep();
  559.         return;
  560.     }
  561. }
  562.  
  563. /* the ball eats the walls and paddles */
  564. Recover_From_Collision()
  565. {
  566.     register Rect *rp = &((**ball.unRgn).rgnBBox);
  567.  
  568.     if (SectRect(rp, &top_wall, &r))
  569.         FillRect(&r, &WALL_PAT);
  570.     else if (SectRect(rp, &bottom_wall, &r))
  571.         FillRect(&r,&WALL_PAT);
  572.     if (SectRect(rp, &l_paddle.r, &r))
  573.         FillRect(&r, &PAD_PAT);
  574.     else if (SectRect(rp, &r_paddle.r, &r))
  575.         FillRect(&r, &PAD_PAT);
  576. }
  577.  
  578. Move_Left_Paddle()
  579. {
  580.     static Point mouseLoc;
  581.     register short newTop, newBottom;
  582.  
  583.     GetMouse(&mouseLoc);
  584.     if (mouseLoc.v != l_paddle.r.top)
  585.     {
  586.         r.left = l_paddle.r.left;
  587.         r.right = l_paddle.r.right;
  588.         if (mouseLoc.v <= winStorage.port.portRect.top)
  589.         {
  590.             newTop = winStorage.port.portRect.top;
  591.             newBottom = newTop + PADLENGTH;
  592.         }
  593.         else if (mouseLoc.v + PADLENGTH >= winStorage.port.portRect.bottom){
  594.             newBottom = winStorage.port.portRect.bottom;
  595.             newTop = newBottom - PADLENGTH;
  596.         }
  597.         else{
  598.             newTop = mouseLoc.v;
  599.             newBottom = newTop + PADLENGTH;
  600.         }
  601.         if (newTop > l_paddle.r.top)
  602.         {
  603.             r.top = l_paddle.r.top;
  604.             r.bottom = (newTop > l_paddle.r.bottom) ? l_paddle.r.bottom: newTop;
  605.         }
  606.         else if (newTop < l_paddle.r.top){
  607.             r.bottom = l_paddle.r.bottom;
  608.             r.top = (newBottom < l_paddle.r.top) ? l_paddle.r.top: newBottom;
  609.         }
  610.         l_paddle.r.top = newTop;
  611.         l_paddle.r.bottom = newBottom;
  612.         EraseRect(&r); 
  613.         FillRect(&l_paddle.r,&PAD_PAT);
  614.     }
  615.     else
  616.         FillRect(&l_paddle.r, &PAD_PAT);
  617. }
  618.  
  619. Move_Right_Paddle()
  620. {
  621.     if (r_paddle.dir == STOPPED)
  622.         FillRect(&r_paddle.r, &PAD_PAT);
  623.     else{
  624.         r.left = r_paddle.r.left;
  625.         r.right = r_paddle.r.right;
  626.         switch (r_paddle.dir)
  627.         {
  628.             case UP:
  629.                 r.bottom = r_paddle.r.bottom;
  630.                 r_paddle.r.top -= r_paddle.speed;
  631.                 r_paddle.r.bottom -= r_paddle.speed;
  632.                 r.top = r_paddle.r.bottom;
  633.             break;
  634.             case DOWN:
  635.                 r.top = r_paddle.r.top;
  636.                 r_paddle.r.top += r_paddle.speed;
  637.                 r_paddle.r.bottom += r_paddle.speed;
  638.                 r.bottom = r_paddle.r.top;
  639.             break;    
  640.         }
  641.         EraseRect(&r); 
  642.         FillRect(&r_paddle.r, &PAD_PAT);
  643.     }
  644. }
  645.  
  646. Move_Ball()
  647. {
  648.     if (ball.on){
  649.         CopyRgn(ball.rgn, ball.oldRgn);
  650.         switch (ball.dir)
  651.         {
  652.             case LEFT:
  653.                 OffsetRgn(ball.rgn, -ball.speed, 0);
  654.             break;
  655.             case RIGHT:
  656.                 OffsetRgn(ball.rgn, ball.speed, 0);
  657.             break;
  658.             case UP_LEFT:
  659.                 OffsetRgn(ball.rgn, -ball.speed, -ball.speed);
  660.             break;
  661.             case UP_RIGHT:
  662.                 OffsetRgn(ball.rgn, ball.speed, -ball.speed);
  663.             break;
  664.             case DOWN_LEFT:
  665.                 OffsetRgn(ball.rgn, -ball.speed, ball.speed);
  666.             break;
  667.             case DOWN_RIGHT:
  668.                 OffsetRgn(ball.rgn, ball.speed, ball.speed);
  669.             break;
  670.         }
  671.         UnionRgn(ball.rgn, ball.oldRgn, ball.unRgn);
  672.         DiffRgn(ball.unRgn, ball.rgn, ball.unRgn);
  673.         EraseRgn(ball.unRgn);
  674.         PaintRgn(ball.rgn);
  675.         Recover_From_Collision();
  676.     }
  677. }
  678.  
  679. Display_Score()
  680. {
  681.     static long i;
  682.     
  683.         if (l_paddle.score < 10)
  684.         {
  685.             title[6] = '0';
  686.             i = l_paddle.score;
  687.             NumToString(i, ((StringPtr) title + 5));
  688.         }
  689.         else{
  690.             i = l_paddle.score;
  691.             NumToString(i, ((StringPtr) title + 6));
  692.         }
  693.         if (r_paddle.score < 10)
  694.         {
  695.             title[28] = '0';
  696.             i = r_paddle.score;
  697.             NumToString(i, ((StringPtr) title + 27));
  698.         }
  699.         else
  700.             {
  701.                 i = r_paddle.score;
  702.                 NumToString(i, ((StringPtr) title + 27));
  703.         }
  704.         /* NumToString inserts a '\0' we don't need */
  705.         *(title + 5) = ' ';
  706.         *(title + 27) = ' ';
  707.         SetWTitle(gameWindow, (StringPtr) title);
  708. }
  709.  
  710. Bleep()
  711. {
  712.     if (sound_on)
  713.     {;
  714. //        if (! SoundDone())
  715. //            StopSound();
  716. //        StartSound((Ptr) &bleep_buf, (long) sizeof(bleep_buf), 0L);
  717.     }
  718. }
  719.  
  720. Blat()
  721. {
  722.     if (sound_on)
  723.     {;
  724. //        if (! SoundDone())
  725. //            StopSound();
  726. //        StartSound((Ptr) &blat_buf, (long) sizeof(blat_buf), 0L);
  727.     }
  728. }
  729.  
  730. /* Every so often, let the Mac's paddle fail to track the ball until
  731.    the ball has passed it by a certain amount.
  732.    This is the heart of a satisfying game. */
  733. short Handicap()
  734. {
  735.     register mac_skill;
  736.  
  737.     switch(skill_level)
  738.     {
  739.         case 1:
  740.             mac_skill = 2;
  741.         break;
  742.         
  743.         case 2:
  744.             mac_skill = 8;
  745.         break;
  746.         case 3:
  747.             mac_skill = 27;
  748.         break;
  749.         
  750.         case 4:
  751.             mac_skill = 64;
  752.         break;
  753.         
  754.         default:
  755.             mac_skill = 2;
  756.         break;
  757.     }
  758.     return ((Random() % mac_skill) == 0) ? 5: 0;
  759. }
  760.  
  761.